#ifndef SERVER_H_
#define SERVER_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <signal.h>

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#include <port_comm.h>
#include <serial_comm.h>
#include <input_reader.h>
#include <util.h>


// This Server will be a singleton
class Server{
 public:
  // Outside interface
  static Server* getServer(void);


  // Deconstructor
  ~Server(void);

  // RUN!!!
  void run(void);

  // Handle Sigs
  static void int_sig_handle(int sig);
  static void pipe_sig_handle(int sig);

 protected:
  // Constructors
  Server(const char* fd_joystick, const char* fd_ardui, int baud, int portno);

  static Server* theServer;

  // Members
  const char* fd_joystick;
  const char* fd_ardui;
  int baud;
  int portno;

  bool running;

  PortComm* port_comm;
  SerialComm* ardui_comm;
  InputReader* input_reader;

  // Methods
  int init(void);
  int init_sigs(void);

  // Member for testing
  // Simulate joystick
#ifdef NO_JOY
  int joy_x;
  int joy_y;
  int joy_z;
  int joy_but_0;
  int joy_but_1;
#endif
};


#endif
